<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>筛选记录列表</title>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 70px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<script type="text/javascript">
    var arrFoundCode = [];
    <c:forEach items="${friBaseList}" var= "module">
    var item  = {"fundRasInsId":"${module.id}","fundRasInsNmShow":"${module.fundRasInsNmShow}"};
    arrFoundCode.push(item);
    </c:forEach>

    var cstId = '${cstId}';
    var prjTypCd = '${prjTypCd}';
    var grid = null;
    var callback = null;
    $(function () {
        initForm();
        initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
        searchBtnEvent();
        clearBtnEvent();
    });

     //初始化表单
     function initForm() {
        $("#searchBar").ligerForm();
     }

    //查询参数
    function getSearchParams() {
        var form = new liger.get("searchBar");
        var data = form.getData();
        data["cstId"] = cstId;
        data["prjTypCd"] = prjTypCd;
        return data;
    }

    //初始化列表
    function initGrid() {
        $("#ligergrid1").ligerGrid({
            url: '<%=path%>/project/prjbscinfo/preInsInfoInitList.do',
            parms: getSearchParams(),
            method: 'get',
            columns: [
                {display: '筛选记录id', name: 'preName', minWidth: 365, align: 'center', enabledSort: false},
                {display: '客户经理', name: 'cstMgrNm', width: 138, align: 'center', enabledSort: false},
                {display: '创建时间', name: 'crtTm', width: 204, align: 'center', enabledSort: false,render:renderDate}
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: false,
            alternatingRow: true,
            detail: {
                height: 'auto',
                onShowDetail: showChildren
            },
            //加载数据后折叠事件
            onAfterShowData: function() {
                 var l = $(".l-grid-row-cell-detailbtn").length;
                 for (var i = l - 1; i >= 0; i--)
                 $(".l-grid-row-cell-detailbtn")[i].click();
            },
            frozen:false
        });
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
     }

    //查询按钮事件
    function searchBtnEvent() {
        $("#searchBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            data["crtTm"] = $("#crtTm").val();
            data["crtTmMin"] = $("#crtTmMin").val();
            data["crtTmMax"] = $("#crtTmMax").val();
            data["cstId"] = cstId;
            data["prjTypCd"] = prjTypCd;
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });
    }

    //清空按钮事件
    function clearBtnEvent() {
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单
                "crtTmMin": " ",
                "crtTmMax":" ",
                "cstMgrNm":" "
            });
        });
    }

     callback = function () {
        grid.reload();
     };

    /**
     * 展开List
     * @param row
     * @param detailPanel
     * @param callback
     */
    function showChildren(row, detailPanel, callback) {
        var gridBox = document.createElement('div');
        $(gridBox).css('margin', 10);
        $(detailPanel).css({
            'padding': 10,
            'box-sizing': 'border-box'
        }).append(gridBox);
        detailGrid = $(gridBox).ligerGrid({
            url: '<%=path%>/project/prjbscinfo/preInsResInfoInitList.do?id=' + row.id,
            method: 'get',
            columns: [
                {
                    display: '机构名称', name: 'insNm', width: 294,
                    enabledSort:true,
                    render: function (rowdata, index, value) {
                        if (rowdata.insId && ("" + rowdata.insId).trim()) {
                            if(arrFoundCode){
                                for (var i=0;i<arrFoundCode.length;i++) {
                                    if(arrFoundCode[i].fundRasInsId == rowdata.insId){
                                        return '<span style="font-weight: bold">' + arrFoundCode[i].fundRasInsNmShow + '</span><br/>';
                                    }
                                }
                            }
                        }else{
                            return '<span style="font-weight: bold">' + rowdata.insNm + '</span><br/>';
                        }
                    }
                },
                { display: '状态', name: 'resSts', minWidth: 236 , enabledSort:true,render:renderResSts},
                {
                    display: '操作',
                    isSort: false,
                    width: 150,
                    render: function (rowdata, rowindex, value) {
                        //已占用的筛选结果不允许选择
                        if("2" == rowdata.resSts){
                            var h = '<a class="sq-button-hasicon" style="opacity: 0.2;" href="javascript:return false;" ';
                            h += '"><i class="sqBtnIco_3"></i>选择</a>'
                            return h;
                        }
                        var h = '<a class="sq-button-hasicon" href="javascript:choosePreInsRow(';
                        //预筛选记录ID
                        h += "'" + row.id + "',";
                        //预筛选结果ID
                        h += "'" + rowdata.id + "',";
                        h += "'" + rowdata.insId + "',";
                        h += "'" + rowdata.insCode + "',";
                        h += "'" + rowdata.insNm + "',";
                        h += "'" + rowdata.resTypCd + "',";
                        //预筛选记录中是否厂商业务
                        h += "'" + row.isSplMfr + "'";
                        h += ')"><i class="sqBtnIco_3"></i>选择</a>'
                        return h;
                    }
                }
            ],
            root: 'rows',
            hideLoadButton: true,
            width: '100%',
            height: 'auto',
            isScroll: false,
            rownumbers: false,  //显示序号
            checkbox: false,
            allowUnSelectRow: false,
            alternatingRow: false,
            onAfterShowData: callback,
            frozen: false,
            usePager: false
        });
    }

    function choosePreInsRow(preRouteId,preResId,insId,insCode,insNm,resTypCd,isSplMfrVal){
        //设置父页面属性
        parent.window.document.getElementById("preRouteId").value = preRouteId;
        parent.window.document.getElementById("preResId").value = preResId;
        parent.window.document.getElementById("fundRasInsId").value = insId;
        parent.window.document.getElementById("insCode").value = insCode;

        //反显机构名称
        var fundRasInsNm = parent.window.document.getElementById("fundRasInsNm");
        $(fundRasInsNm).html(insNm);

        var fundRasInsNmShow = parent.window.document.getElementById("fundRasInsNmShow");
        var fundRasInsNmTextShow = insNm;
        if (insId && ("" + insId).trim()) {
            if(arrFoundCode){
                for (var i=0;i<arrFoundCode.length;i++) {
                    if(arrFoundCode[i].fundRasInsId == insId){
                        fundRasInsNmTextShow = arrFoundCode[i].fundRasInsNmShow;
                        break;
                    }
                }
            }
        }
        $(fundRasInsNmShow).html(fundRasInsNmTextShow);



        var isSplMfr = parent.window.document.getElementById("isSplMfr");
        //是否厂商业务
        if (prjTypCd != ProjectConstant.PRJ_TYP_CD_CDDYWUL && prjTypCd != ProjectConstant.PRJ_TYP_CD_ESCJYD
                && prjTypCd != ProjectConstant.PRJ_TYP_CD_OWNJYD) {
            if(isSplMfrVal == "0"){
                parent.window.displayIsSplMfr(0);
                //否删除方案
                top.$.ligerDialog.confirm("修改是否厂商为否时将会：删除现有报价及支付表；确定修改么？", function (flag) {
                    if(flag == false) {
                        isSplMfr.value = 1;
                        parent.window.displayIsSplMfr(1);
                    }else{
                        isSplMfr.value = 0;
                        parent.window.displayIsSplMfr(0);
                        parent.window.document.getElementById("calQuatPrpsId").value = "";
                        parent.$("#isSplMfrShowDiv").hide();
                    }
                });
            }
        }

        var selectid= parent.$("#isInsBiz").ligerGetComboBoxManager();
        if(StringUtils.isNotEmpty(resTypCd) && resTypCd == 1){
            selectid.setValue(1);
            selectid.setText("是");
            parent.$("#isInsBiz").val(1);
        }else{
            selectid.setValue(0);
            selectid.setText("否");
            parent.$("#isInsBiz").val(0);
        }
        if(isSplMfrVal=="1"){
            isSplMfr.value = 1;
            parent.window.displayIsSplMfr(1);
            parent.window.chooseMfrQuatPage();
        }
        //关闭弹框
        frameElement.dialog.close();
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    //格式化筛选状态 0-筛选中,1-未占用,2-已占用
    function renderResSts(rowdata,index, value){
        var resStsStr = "";
        if("0" == value){
            resStsStr = "筛选中";
        }
        if("1" == value){
            resStsStr = "未占用";
        }
        if("2" == value){
            resStsStr = "已占用";
        }
        return resStsStr;
    }

</script>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">创建日期</div>
                    <div class="field">
                        <input ligerui="width: 100" name="crtTmMin" id="crtTmMin" type="text" class="ui-datepicker" value="">
                        -
                        <input ligerui="width: 100" name="crtTmMax" id="crtTmMax" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户经理</div>
                    <div class="field">
                        <input name="cstMgrNm" id="cstMgrNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="clearFix"></div>
                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round"></i>查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round"></i>清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

</body>
</html>
